#install.packages("effectR")

library("effectR")
library(tidyverse)
setwd("C:\\Users\\dell\\Desktop\\")

fasta.file <- "RxLR_V2.fasta"

ORF <- seqinr::read.fasta(fasta.file)

REGEX <- regex.search(seq=ORF, motif = "custom", 
            reg.pat = "^\\w{20}\\w{1,100}[RQG]\\wLR") #\\w{1,40}[ED][ED][RK] 

head(REGEX)

#regex.search(seq=ORF, motif = "custom", 
#reg.pat = "^\\w{10,40}\\w{1,96}R\\wLR\\w{1,40}[ED][ED][RK]\\w{1-20}[WYL]")
RxLR.effectors <- effector.summary(REGEX, motif = "custom",
                                   reg.pat = "^\\w{20}\\w{1,100}[RQG]\\wLR")

RxLR.effectors <- effector.summary(REGEX, motif = "RxLR")

head(RxLR.effectors$motif.table, n = 5)
write.table(RxLR.effectors$motif.table, file = "RxLR_motif_predict.xls", sep='\t', quote = F)

############ Install MAFFT for HMMER search
candidate.rxlr <- hmm.search(original.seq = fasta.file, regex.seq = REGEX)
# Summarizing the predictions from step 1 and step 2 using the effectR.summary() function (Step 3a).
# The summary of non-redundant RxLR predicted effectors will be stored in the RxLR.effector$consensus.sequences objects
# The table of motif number and position will be stored in the RxLR.effectors$motif.table object
RxLR.effectors <- effector.summary(candidate.rxlr, motif = "RxLR")
# What is the number of non-reduntant RxLR effectors predicted by step 1 and step 2?

length(RxLR.effectors$consensus.sequences)
head(RxLR.effectors$motif.table, n = 5)
#Citation: effectR: An Expandable R Package to Predict Candidate RxLR and CRN Effectors in Oomycetes Using Motif Searches